import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class FlexTest extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
        appBar: AppBar(
          title: Text('弹性布局测试'),
          centerTitle: true,
        ),
        body: Flex(
          direction: Axis.vertical,
          children: <Widget>[
            Flex(
              direction: Axis.horizontal,
              children: <Widget>[
                Expanded(
                  flex: 1,
                  child: Container(
                    height: 30,
                    color: Colors.purple,
                  ),
                ),
                Expanded(
                  flex: 10,
                  child: Container(
                    height: 30,
                    color: Colors.green,
                  ),
                )
              ],
            ),
            Padding(
                padding: EdgeInsets.only(top: 20),
                child: SizedBox(
                  height: 100,
                  child: Flex(
                    direction: Axis.vertical,
                    children: <Widget>[
                      Expanded(
                        flex: 2,
                        child: Container(
                          height: 30.0,
                          color: Colors.red,
                        ),
                      ),
                      Expanded(
                        flex: 1,
                        child: Container(
                          color: Colors.purple,
                        ),
                      )
                    ],
                  ),
                )),
            Divider(
              height: 30,
              color: Colors.amber,
            ),
            Wrap(
              spacing: 50,
              runSpacing: 20,
              alignment: WrapAlignment.start,
              direction: Axis.horizontal,
              children: <Widget>[
                new Chip(
                  avatar: new CircleAvatar(
                      backgroundColor: Colors.blue, child: Text('A')),
                  label: new Text('Hamilton'),
                  deleteIcon: Icon(Icons.delete),
                  onDeleted: () {},
                ),
                new Chip(
                  avatar: new CircleAvatar(
                      backgroundColor: Colors.blue, child: Text('M')),
                  label: new Text('Lafayette'),
                ),
                new Chip(
                  avatar: new CircleAvatar(
                      backgroundColor: Colors.blue, child: Text('H')),
                  label: new Text('Mulligan'),
                ),
                new Chip(
                  avatar: new CircleAvatar(
                      backgroundColor: Colors.blue, child: Text('J')),
                  label: new Text('Laurens'),
                ),
              ],
            ),
            Divider(
              height: 30,
              color: Colors.amber,
            ),
            Container(
              color: Colors.green,
              child: Align(
                widthFactor: 2,
                heightFactor: 2,
                alignment: Alignment(0, 0),
                child: FlutterLogo(
                  size: 60,
                ),
              ),
            ),
            Container(
              color: Colors.purple,
              child: Align(
                widthFactor: 2,
                heightFactor: 2,
                alignment: FractionalOffset(0.5, 0.5),
                child: FlutterLogo(
                  size: 60,
                ),
              ),
            )
          ],
        ));
  }
}

class StackTest extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text('Stack测试'),
      ),
      body: Stack(
        alignment: Alignment.center,
        fit: StackFit.expand,
        children: <Widget>[
          Positioned(
            left: 8.0,
            child: Text('11111'),
          ),
          Positioned(
            child: Container(
              child: Center(
                child: Text('2222'),
              ),
              color: Colors.green,
            ),
          ),
          Positioned(
            top: 20,
            child: Text('44444'),
          ),
        ],
      ),
    );
  }
}

class BoxSizeBoxTest extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    Widget testWidget = DecoratedBox(
      decoration: BoxDecoration(color: Colors.purple),
    );
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text('Box'),
      ),
      drawer: Drawer(
        child: Text("ceshi"),
      ),
      endDrawer: Drawer(),
      body: Align(
        alignment: FractionalOffset(0.5, 0),
        child: Column(
          children: <Widget>[
            ConstrainedBox(
//            constraints: BoxConstraints(
//              minWidth: double.infinity,
//              minHeight: 100,
//            ),
              constraints: BoxConstraints.tight(Size(70, 70)),
              child: Container(
                height: 60,
                child: testWidget,
              ),
            ),
            ConstrainedBox(
              constraints: BoxConstraints(maxWidth: 100, maxHeight: 50),
              child: ConstrainedBox(
                constraints: BoxConstraints(maxWidth: 90, maxHeight: 60),
                child: SizedBox(
                  width: 200,
                  height: 200,
                  child: testWidget,
                ),
              ),
            ),
            Padding(
              padding: EdgeInsets.only(top: 20),
              child: DecoratedBox(
                position: DecorationPosition.background,
                decoration: BoxDecoration(
                  gradient: LinearGradient(
                      colors: [Colors.red, Colors.yellow, Colors.purple]),
                  borderRadius: BorderRadius.circular(4),
                  boxShadow: [
                    BoxShadow(
                        color: Colors.black54,
                        offset: Offset(2.0, 2.0),
                        blurRadius: 4.0),
                  ],
                ),
                child: Padding(
                  padding: EdgeInsets.symmetric(vertical: 10, horizontal: 20),
                  child: Text(
                    'Login',
                    style: TextStyle(color: Colors.white),
                  ),
                ),
              ),
            ),
            Padding(
              padding: EdgeInsets.only(top: 20),
              child: Container(
                width: 200,
                color: Colors.purple,
                child: Transform(
                  alignment: Alignment.topCenter,
                  transform: Matrix4.skewY(0.3),
                  child: Container(
                    padding: const EdgeInsets.all(20),
                    color: Colors.yellow,
                    child: Text('Apartment for rent!'),
                  ),
                ),
              ),
            ),
            Padding(
              padding: EdgeInsets.only(top: 30),
              child: DecoratedBox(
                decoration: BoxDecoration(color: Colors.red),
                child: Transform.translate(
                  offset: Offset(-10, 0),
                  child: Text('hello word'),
                ),
              ),
            ),
            Padding(
              padding: EdgeInsets.only(top: 30),
              child: DecoratedBox(
                decoration: BoxDecoration(color: Colors.green),
                child: Transform.rotate(
                  angle: 1.57,
                  child: Text("hello word"),
                ),
              ),
            ),
            Padding(
              padding: EdgeInsets.only(top: 30),
              child: DecoratedBox(
                  decoration: BoxDecoration(color: Colors.green),
                  child: RotatedBox(
                    quarterTurns: 1,
                    child: Text('hellor word'),
                  )),
            ),
            Container(
              constraints: BoxConstraints.tightFor(width: 200,height: 100),
              decoration: BoxDecoration(
                gradient: LinearGradient(colors: [Colors.green, Colors.amber]),
                borderRadius: BorderRadius.circular(4),
                boxShadow: [
                  BoxShadow(
                    color: Colors.black,
                    offset: Offset(2,2),
                    blurRadius: 2
                  ),
                ],
              ),
              alignment: Alignment.center,
              transform: Matrix4.rotationZ(.1),
              margin: EdgeInsets.all(20),
              child: Text(
                '5.20',
                style: TextStyle(fontSize: 32, color: Colors.white),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
